﻿using System.Collections.Generic;
using System.IO;

namespace Codebook.Helpers
{
    public static class DirectoryHelper
    {
        public static string[] GetAllFiles(string path, string searchPattern)
        {
            var files = new List<string>();
            var folders = new Queue<string>();

            folders.Enqueue(path);
            while (folders.Count > 0) {
                var folder = folders.Dequeue();
                foreach (var directory in Directory.GetDirectories(folder)) {
                    folders.Enqueue(directory);
                }
                foreach (var file in Directory.GetFiles(folder, searchPattern)) {
                    files.Add(file);
                }
            }

            return files.ToArray();
        }

    }
}
